<template>
  <div>
    <a-row>
      <!-- 调课课表取 -->
      <div>
        <a-col :span='12'>
          <a-row>
            <!-- table区域  左边第一个课表模块 -begin -->
            <div class="table-page-search-wrapper">
              <a-form layout="inline" @keyup.enter.native="searchQuery">
                <a-row :gutter="24">
                  <a-col :md="5" :sm="5">
                    <a-form-model-item label="年级" prop="queryParam1.gradeId">
                      <j-dict-select-tag @change='changeGradeId1' v-model="queryParam1.gradeId" placeholder="请选择年级" :dictCode="queryParamDictSelect1.gradeIdSclect"/>
                    </a-form-model-item>
                  </a-col>
                  <a-col :md="6" :sm="5">
                    <a-form-model-item label="班级" prop="queryParam1.classId">
                      <j-dict-select-tag v-model="queryParam1.classId" @change='changeClassId1()' placeholder="请选择班级" :dictCode="queryParamDictSelect1.classIdSclect"/>
                    </a-form-model-item>
                  </a-col>
                  <a-col :md="8" :sm="5">
                    <a-form-model-item label="课表" prop="queryParam1.courseArrangeId">
                      <j-dict-select-tag v-model="queryParam1.courseArrangeId" @change='handleGetDataChange(1)' placeholder="请选择课表" :dictCode="queryParamDictSelect1.courseArrangeIdSclect"/>
                    </a-form-model-item>
                  </a-col>
                  <a-col :md="2" :sm="5" style='float: right;margin-right: 15px;'>
                    <a-form-model-item label="" prop="">
                      <a-button @click='handleGetDataChangeContradiction(1)' type='primary' style='background: #e5700a;border: none;'><a-icon type="fullscreen-exit" /></a-button>
                    </a-form-model-item>
                  </a-col>
                  <a-col :md="2" :sm="5" style='float: right;'>
                    <a-form-model-item label="" prop="">
                      <a-button @click='handleGetDataChange(1)' type='primary'><a-icon type="sync" /></a-button>
                    </a-form-model-item>
                  </a-col>

                </a-row>
              </a-form>
            </div>
          </a-row>
          <div style='float:left;text-align: center;background: #ffffff;border: 1px solid #e2e2e2;'>
            <div style='width: 90px;float: left;'>
              <div  class='week-t'><span>节次</span></div>
              <div class='week-c' style='font-size: 14px;background-color: #fafafa;' v-for='item in courseOneData1' :key='item.courseArrangeAtomId' slot='item'>
                <div>{{ item.courArraAtomSectionname }}</div>
                <div>[{{ item.courArraAtomStartTime }}-{{ item.courArraAtomEndTime }}]</div>
              </div>
            </div>

            <div style='width: 110px;float: left;'>
              <div class='week-t'><span>星期一</span></div>
              <div v-for='item in courseOneData1' :key='item.courseArrangeAtomId' slot='item'>
                <!--            <div class='week-c' :style="{'background':item.relarrangeContradictionColor}">-->
                <div class='week-c' :style="{'background':item.arrangeContradictionColor}" @click='selectBt(item,1)'>
                  <div><span>{{ item.subjectName }} </span> <span>{{ item.teacherName }}</span></div>
                  <div>{{ item.classNicknameView }} </div>
                </div>
              </div>
            </div>
            <div style='width: 110px;float: left;'>
              <div class='week-t'><span>星期二</span></div>
              <div v-for='item in courseOneData2' :key='item.courseArrangeAtomId' slot='item'>
                <div class='week-c' :style="{'background':item.arrangeContradictionColor}" @click='selectBt(item,1)'>
                  <div><span>{{ item.subjectName }} </span> <span>{{ item.teacherName }}</span></div>
                  <div>{{ item.classNicknameView }} </div>
                </div>
              </div>
            </div>
            <div style='width: 110px;float: left;'>
              <div class='week-t'><span>星期三</span></div>
              <div v-for='item in courseOneData3' :key='item.courseArrangeAtomId' slot='item'>
                <div class='week-c' :style="{'background':item.arrangeContradictionColor}" @click='selectBt(item,1)'>
                  <div><span>{{ item.subjectName }} </span> <span>{{ item.teacherName }}</span></div>
                  <div>{{ item.classNicknameView }} </div>
                </div>
              </div>
            </div>
            <div style='width: 110px;float: left;'>
              <div class='week-t'><span>星期四</span></div>
              <div v-for='item in courseOneData4' :key='item.courseArrangeAtomId' slot='item'>
                <div class='week-c' :style="{'background':item.arrangeContradictionColor}" @click='selectBt(item,1)'>
                  <div><span>{{ item.subjectName }} </span> <span>{{ item.teacherName }}</span></div>
                  <div>{{ item.classNicknameView }} </div>
                </div>
              </div>
            </div>
            <div style='width: 110px;float: left;'>
              <div class='week-t'><span>星期五</span></div>
              <div v-for='item in courseOneData5' :key='item.courseArrangeAtomId' slot='item'>
                <div class='week-c' :style="{'background':item.arrangeContradictionColor}" @click='selectBt(item,1)'>
                  <div><span>{{ item.subjectName }} </span> <span>{{ item.teacherName }}</span></div>
                  <div>{{ item.classNicknameView }} </div>
                </div>
              </div>
            </div>
            <div style='width: 80px;float: left;'>
              <div class='week-t'><span>星期六</span></div>
              <div v-for='item in courseOneData6' :key='item.courseArrangeAtomId' slot='item'>
                <div class='week-c' :style="{'background':item.arrangeContradictionColor}" @click='selectBt(item,1)'>
                  <div><span>{{ item.subjectName }} </span> <span>{{ item.teacherName }}</span></div>
                  <div>{{ item.classNicknameView }} </div>
                </div>
              </div>
            </div>
            <div style='width: 80px;float: left;'>
              <div class='week-t'><span>星期天</span></div>
              <div v-for='item in courseOneData7' :key='item.courseArrangeAtomId' slot='item'>
                <div class='week-c' :style="{'background':item.arrangeContradictionColor}" @click='selectBt(item,1)'>
                  <div><span>{{ item.subjectName }} </span> <span>{{ item.teacherName }}</span></div>
                  <div>{{ item.classNicknameView }} </div>
                </div>
              </div>
            </div>
          </div>
        </a-col>

        <a-col :span='12'>
          <a-row>
            <!-- table区域 右边第二个课表模块 -begin -->
            <div class="table-page-search-wrapper">
              <a-form layout="inline" @keyup.enter.native="searchQuery">
                <a-row :gutter="24">
                  <a-col :md="5" :sm="5">
                    <a-form-model-item label="年级" prop="gradeId">
                      <j-dict-select-tag @change='changeGradeId2' v-model="queryParam2.gradeId" placeholder="请选择年级" :dictCode="queryParamDictSelect2.gradeIdSclect" />
                    </a-form-model-item>
                  </a-col>
                  <a-col :md="6" :sm="5">
                    <a-form-model-item label="班级" prop="classId">
                      <j-dict-select-tag v-model="queryParam2.classId"  @change='changeClassId2()' placeholder="请选择班级" :dictCode="queryParamDictSelect2.classIdSclect"/>
                    </a-form-model-item>
                  </a-col>
                  <a-col :md="8" :sm="5">
                    <a-form-model-item label="课表" prop="queryParam2.courseArrangeId">
                      <j-dict-select-tag v-model="queryParam2.courseArrangeId" @change='handleGetDataChange(2)' placeholder="请选择课表" :dictCode="queryParamDictSelect2.courseArrangeIdSclect"/>
                    </a-form-model-item>
                  </a-col>
                  <a-col :md="2" :sm="5" style='float: right;margin-right: 10px;'>
                    <a-form-model-item label="" prop="">
                      <a-button @click='handleGetDataChangeContradiction(2)' type='primary' style='background: #e5700a;border: none;'><a-icon type="fullscreen-exit" /></a-button>
                    </a-form-model-item>
                  </a-col>
                  <a-col :md="2" :sm="5" style='float: right;'>
                    <a-form-model-item label="" prop="">
                      <a-button @click='handleGetDataChange(2)' type='primary'><a-icon type="sync" /></a-button>
                    </a-form-model-item>
                  </a-col>
                </a-row>
              </a-form>
            </div>
          </a-row>
          <div style='float:left;text-align: center;background: #ffffff;border: 1px solid #e2e2e2;'>
            <div style='width: 90px;float: left;'>
              <div  class='week-t'><span>节次</span></div>
              <div class='week-c' style='font-size: 14px;background-color: #fafafa;' v-for='item in courseTwoData1' :key='item.courseArrangeAtomId' slot='item'>
                <div>{{ item.courArraAtomSectionname }}</div>
                <div>[{{ item.courArraAtomStartTime }}-{{ item.courArraAtomEndTime }}]</div>
              </div>
            </div>

            <div style='width: 110px;float: left;'>
              <div class='week-t'><span>星期一</span></div>
              <div v-for='item in courseTwoData1' :key='item.courseArrangeAtomId' slot='item'>
                <!--            <div class='week-c' :style="{'background':item.relarrangeContradictionColor}">-->
                <div class='week-c' :style="{'background':item.arrangeContradictionColor}" @click='selectBt(item,2)'>
                  <div><span>{{ item.subjectName }} </span> <span>{{ item.teacherName }}</span></div>
                  <div>{{ item.classNicknameView }} </div>
                </div>
              </div>
            </div>
            <div style='width: 110px;float: left;'>
              <div class='week-t'><span>星期二</span></div>
              <div v-for='item in courseTwoData2' :key='item.courseArrangeAtomId' slot='item'>
                <div class='week-c' :style="{'background':item.arrangeContradictionColor}" @click='selectBt(item,2)'>
                  <div><span>{{ item.subjectName }} </span> <span>{{ item.teacherName }}</span></div>
                  <div>{{ item.classNicknameView }} </div>
                </div>
              </div>
            </div>
            <div style='width: 110px;float: left;'>
              <div class='week-t'><span>星期三</span></div>
              <div v-for='item in courseTwoData3' :key='item.courseArrangeAtomId' slot='item'>
                <div class='week-c' :style="{'background':item.arrangeContradictionColor}" @click='selectBt(item,2)'>
                  <div><span>{{ item.subjectName }} </span> <span>{{ item.teacherName }}</span></div>
                  <div>{{ item.classNicknameView }} </div>
                </div>
              </div>
            </div>
            <div style='width: 110px;float: left;'>
              <div class='week-t'><span>星期四</span></div>
              <div v-for='item in courseTwoData4' :key='item.courseArrangeAtomId' slot='item'>
                <div class='week-c' :style="{'background':item.arrangeContradictionColor}" @click='selectBt(item,2)'>
                  <div><span>{{ item.subjectName }} </span> <span>{{ item.teacherName }}</span></div>
                  <div>{{ item.classNicknameView }} </div>
                </div>
              </div>
            </div>
            <div style='width: 110px;float: left;'>
              <div class='week-t'><span>星期五</span></div>
              <div v-for='item in courseTwoData5' :key='item.courseArrangeAtomId' slot='item'>
                <div class='week-c' :style="{'background':item.arrangeContradictionColor}" @click='selectBt(item,2)'>
                  <div><span>{{ item.subjectName }} </span> <span>{{ item.teacherName }}</span></div>
                  <div>{{ item.classNicknameView }} </div>
                </div>
              </div>
            </div>
            <div style='width: 80px;float: left;'>
              <div class='week-t'><span>星期六</span></div>
              <div v-for='item in courseTwoData6' :key='item.courseArrangeAtomId' slot='item'>
                <div class='week-c' :style="{'background':item.arrangeContradictionColor}" @click='selectBt(item,2)'>
                  <div><span>{{ item.subjectName }} </span> <span>{{ item.teacherName }}</span></div>
                  <div>{{ item.classNicknameView }} </div>
                </div>
              </div>
            </div>
            <div style='width: 80px;float: left;'>
              <div class='week-t'><span>星期天</span></div>
              <div v-for='item in courseTwoData7' :key='item.courseArrangeAtomId' slot='item'>
                <div class='week-c' :style="{'background':item.arrangeContradictionColor}" @click='selectBt(item,2)'>
                  <div><span>{{ item.subjectName }} </span> <span>{{ item.teacherName }}</span></div>
                  <div>{{ item.classNicknameView }} </div>
                </div>
              </div>
            </div>
          </div>
        </a-col>
      </div>
    </a-row>

    <!-- 所选格子数据显示 -->
    <a-row>
      <div style='margin-top: 20px;background: #d6dff3;'>
        <a-col :span='10' style='text-align: left;'>
          <p v-if='adjustmentCourseOneData.subjectName != null' style='font-size: 16px;'>
            <span style=''>已选择：</span>
            <span style='color: #e50a36;'>{{ adjustmentCourseOneData.classNicknameView }}</span>
            <span style='color: #e50a36;'> 星期{{ adjustmentCourseOneData.courArraAtomWeekday }}</span>
            <span style='color: #e50a36;'> {{ adjustmentCourseOneData.courArraAtomSectionname }}</span>

            <span style='margin-left: 10px;'>
              <span style='margin-left: 10px;'>科目：</span><span style='color: #058ee8;'>{{ adjustmentCourseOneData.subjectName }}</span>
              <span style='margin-left: 10px;'>任课教师：</span><span style='color: #058ee8;'>{{ adjustmentCourseOneData.teacherName }}</span>
              <span style='margin-left: 10px;'>教室：</span><span style='color: #058ee8;'>{{ adjustmentCourseOneData.classNickname }}</span>
              <span style='margin-left: 10px;' v-if='adjustmentCourseOneData.subjectName === ""'>此节课无安排</span><br/>
              <a-button type="primary" style='border: none;margin-right: 10px;' @click='clearSelectOne()'>清空</a-button>
              <span style='color: #e50a36;' v-if='adjustmentCourseOneData.courseArrangeId == null || adjustmentCourseOneData.courseArrangeId == "" || adjustmentCourseOneData.courseArrangeStatus == null || adjustmentCourseOneData.courseArrangeStatus == ""  || adjustmentCourseOneData.courseArrangeStatus === "4" || adjustmentCourseOneData.courseArrangeStatus === "5" || adjustmentCourseOneData.courseArrangeId.search(",") >=0  '>状态：不可调换（课表已发布或已下线不可更改，或多个课表或多节课不允许调换）</span>
              <span style='color: #2ccd74;' v-if='!(adjustmentCourseOneData.courseArrangeId == null || adjustmentCourseOneData.courseArrangeId == "" || adjustmentCourseOneData.courseArrangeStatus == null || adjustmentCourseOneData.courseArrangeStatus == ""  || adjustmentCourseOneData.courseArrangeStatus === "4" || adjustmentCourseOneData.courseArrangeStatus === "5" || adjustmentCourseOneData.courseArrangeId.search(",") >=0  )' >状态：可调换</span>
            </span>
          </p>
        </a-col>
        <!-- 调换课程 -->
        <a-col :span='4' style='text-align: center'>
          <a-button type="primary" style='background: #e50a36;border:none;border: none;' @click='adjustmentCourseModal'>
            <a-icon style='font-size: 18px;' type='retweet' />
            调换课
          </a-button>
          <a-button type="primary" style='background: #e5700a;border:none;border: none;margin-left: 10px;' @click='adjustmentCoursePutModal'>
            <a-icon style='font-size: 18px;' type='form' />
            编辑课
          </a-button>
        </a-col>
        <a-col :span='10' style='text-align: right;'>
          <p v-if='adjustmentCourseTwoData.subjectName != null' style='font-size: 16px;'>
            <span style=''>已选择：</span>
            <span style='color: #e50a36;'>{{ adjustmentCourseTwoData.classNicknameView }}</span>
            <span style='color: #e50a36;'> 星期{{ adjustmentCourseTwoData.courArraAtomWeekday }}</span>
            <span style='color: #e50a36;'> {{ adjustmentCourseTwoData.courArraAtomSectionname }}</span>

            <span style='margin-left: 10px;'>
              <span style='margin-left: 10px;'>科目：</span><span style='color: #058ee8;'>{{ adjustmentCourseTwoData.subjectName }}</span>
              <span style='margin-left: 10px;'>任课教师：</span><span style='color: #058ee8;'>{{ adjustmentCourseTwoData.teacherName }}</span>
              <span style='margin-left: 10px;'>教室：</span><span style='color: #058ee8;'>{{ adjustmentCourseTwoData.classNickname }}</span>
              <span style='margin-left: 10px;' v-if='adjustmentCourseTwoData.subjectName === ""'>此节课无安排</span><br/>
              <a-button type="primary" style='border: none;margin-right: 10px;' @click='clearSelectTwo()'>清空</a-button>
<!--              <span style='color: #e50a36;' v-if='adjustmentCourseOneData.courseArrangeStatus === 4 || adjustmentCourseOneData.courseArrangeStatus === 5'>状态：不可调换（已发布或已下线）</span>-->
<!--              <span style='color: #2ccd74;' v-if='adjustmentCourseOneData.courseArrangeStatus !== 4 || adjustmentCourseOneData.courseArrangeStatus !== 5'>状态：可调换</span>-->
                 <span style='color: #e50a36;' v-if='adjustmentCourseTwoData.courseArrangeId == null || adjustmentCourseTwoData.courseArrangeId == "" || adjustmentCourseTwoData.courseArrangeStatus == null || adjustmentCourseTwoData.courseArrangeStatus == ""  || adjustmentCourseTwoData.courseArrangeStatus === "4" || adjustmentCourseTwoData.courseArrangeStatus === "5" || adjustmentCourseTwoData.courseArrangeId.search(",") >=0  '>状态：不可调换（课表已发布或已下线不可更改，或多个课表或多节课不允许调换）</span>
              <span style='color: #2ccd74;' v-if='!(adjustmentCourseTwoData.courseArrangeId == null || adjustmentCourseTwoData.courseArrangeId == "" || adjustmentCourseTwoData.courseArrangeStatus == null || adjustmentCourseTwoData.courseArrangeStatus == ""  || adjustmentCourseTwoData.courseArrangeStatus === "4" || adjustmentCourseTwoData.courseArrangeStatus === "5" || adjustmentCourseTwoData.courseArrangeId.search(",") >=0  )' >状态：可调换</span>

            </span>
          </p>
        </a-col>

        <!-- ========调换===============调换课程对话框 -->
        <div>
          <a-modal title="调换课程-选择调换模式" :visible="adjustmentCourseVisible" @ok="handleAdjustmentCourseOk" @cancel="adjustmentCourseVisible = false" width='40%'>
            <a-row>
              <a-col :span="24">
                <a-form-model-item label="选择调换项" prop="" v-if='adjustmentCourseOneData != null && adjustmentCourseTwoData != null'>
                    <a-row>
                      <a-col :span='9'>
                        <a-card :title="adjustmentCourseOneData.classNicknameView + ' ' + '星期' + adjustmentCourseOneData.courArraAtomWeekday + ' ' +adjustmentCourseOneData.courArraAtomSectionname" style="width: 100%;">
                          <p>科目：<span style='color: #058ee8;'>{{ adjustmentCourseOneData.subjectName }}</span></p>
                          <p>任课教师：<span style='color: #058ee8;'>{{ adjustmentCourseOneData.teacherName }}</span></p>
                          <p>教室：<span style='color: #058ee8;'>{{ adjustmentCourseOneData.classNickname }}</span></p>
                          <p>单双周：
                            <j-dict-select-tag v-model='adjustmentCourseOneData.courArraAtomIzSingle' placeholder='请选择单双周'
                                                    dictCode='cour_arra_atom_iz_single' style='width: 150px'/>
                          </p>
                          <p><span style='' v-if='adjustmentCourseOneData.subjectName === ""'>此节课无安排</span></p>
                        </a-card>
                      </a-col>
                      <a-col :span='6'>
                        <a-checkbox-group v-model:value="adjustmentCourseSelectKey" style='width: 100%;text-align: center;' value='4'>
                          <p><a-checkbox value="4">科 目</a-checkbox><br/></p>
                          <p><a-checkbox value="3">教 师</a-checkbox><br/></p>
                          <p><a-checkbox value="2">教 室</a-checkbox><br/></p>
                          <p><a-checkbox value="7">单双周</a-checkbox><br/></p>
                          <p style='color: #b4b4b4;'>* 教室一般无需调换</p>
                          <a-button type="primary" style='height: 25px;margin-top: 20px;' @click='allSelectKey'>全 选</a-button>
                        </a-checkbox-group>
                      </a-col>
                      <a-col :span='9'>
                        <a-card :title="adjustmentCourseTwoData.classNicknameView + ' ' + '星期' + adjustmentCourseTwoData.courArraAtomWeekday + ' ' +adjustmentCourseTwoData.courArraAtomSectionname" style="width: 100%;">
                          <p>科目：<span style='color: #058ee8;'>{{ adjustmentCourseTwoData.subjectName }}</span></p>
                          <p>任课教师：<span style='color: #058ee8;'>{{ adjustmentCourseTwoData.teacherName }}</span></p>
                          <p>教室：<span style='color: #058ee8;'>{{ adjustmentCourseTwoData.classNickname }}</span></p>
                          <p>单双周：
                            <j-dict-select-tag v-model='adjustmentCourseTwoData.courArraAtomIzSingle' placeholder='请选择单双周'
                                               dictCode='cour_arra_atom_iz_single' style='width: 150px'/>
                          </p>
                          <p><span style='' v-if='adjustmentCourseTwoData.subjectName === ""'>此节课无安排</span></p>
                        </a-card>
                      </a-col>
                    </a-row>
                    <p style='line-height: 25px;'>
                      <span>说 明：</span><br/>
                      <span style='color: #e50a36;'>这里是永久调换操作，不是临时调换，谨慎操作！。</span><br/>
                      <span>课程两两调换是时，此处勾选的项的相关数据部分，将进行相互调换。</span><br/>
                      <span>请认真查看，谨慎操作！</span><br/>
                    </p>
                </a-form-model-item>
              </a-col>
            </a-row>
          </a-modal>
        </div>

        <div>
          <a-modal title="调换结果" :visible="adjustmentCourseStatusVisible" @ok="" @cancel="adjustmentCourseStatusVisible = false" width='40%'>
            <a-row>
              <template>
                <a-result
                  status="success"
                  title="恭喜您，课程调换成功!"
                  sub-title=""
                >
                  <template #extra>
                  </template>
                </a-result>
              </template>
            </a-row>
          </a-modal>
        </div>
        <!-- =======调换================调换课程对话框 -->

        <!-- =======编辑================编辑课程对话框 -->
        <div>
          <a-modal title="编辑课程-选择编辑模式" :visible="adjustmentCoursePutVisible" @ok="handleAdjustmentCoursePutOk" @cancel="adjustmentCoursePutVisible = false" width='40%'>
            <a-row>
              <a-col :span="24">
                <a-form-model-item label="选择编辑项" prop="" v-if='adjustmentCoursePutData != null'>
                  <a-row>
                    <a-col :span='9'>
                      <a-card :title="adjustmentCoursePutData.classNicknameView + ' ' + '星期' + adjustmentCoursePutData.courArraAtomWeekday + ' ' +adjustmentCoursePutData.courArraAtomSectionname" style="width: 100%;">
                        <p>科目：<span style='color: #058ee8;'>{{ adjustmentCoursePutData.subjectName }}</span></p>
                        <p>任课教师：<span style='color: #058ee8;'>{{ adjustmentCoursePutData.teacherName }}</span></p>
                        <p>教室：<span style='color: #058ee8;'>{{ adjustmentCoursePutData.classNickname }}</span></p>
                        <p>单双周：
                          <j-dict-select-tag v-model='adjustmentCoursePutData.courArraAtomIzSingle' placeholder='请选择单双周'
                                             dictCode='cour_arra_atom_iz_single' style='width: 150px'/>
                        </p>
                        <p><span style='' v-if='adjustmentCoursePutData.subjectName === ""'>此节课无安排</span></p>
                      </a-card>
                      <p style='line-height: 25px;'>
                        <span>编辑课程说明：</span><br/>
                        <span style='color: #e50a36;'>这里是永久编辑操作，不是临时编辑，谨慎操作！。</span><br/>
                        <span>课程编辑时，此处勾选的项的相关数据部分，将进行编辑。</span><br/>
                        <span>请认真查看，谨慎操作！</span><br/>
                      </p>
                    </a-col>
                    <a-col :span='6'>
                      <a-checkbox-group v-model:value="adjustmentCourseSelectKey" style='width: 100%;text-align: center;' value='4'>
                        <p><a-checkbox value="4">科 目</a-checkbox><br/></p>
                        <p><a-checkbox value="3">教 师</a-checkbox><br/></p>
                        <p><a-checkbox value="2">教 室</a-checkbox><br/></p>
                        <p><a-checkbox value="7">单双周</a-checkbox><br/></p>
                        <p style='color: #b4b4b4;'>* 教室一般无需调换</p>
                        <a-button type="primary" style='height: 25px;margin-top: 20px;' @click='allSelectKey'>全 选</a-button>
                      </a-checkbox-group>
                    </a-col>
                    <a-col :span='9'>
                      <a-card title="选择编辑数据" style="width: 100%;">
                        <a-col :span="24">
<!--                          <a-form-model-item label="科目" prop="subjectId">-->
<!--                            <j-dict-select-tag v-model='adjustmentCoursePutParams.subjectId' placeholder='请选择科目'-->
<!--                                               dictCode='cou_subject,subject_name,id' style='width: 100%'/>-->
<!--                          </a-form-model-item>-->

                          <a-form-model-item label="科目"  prop="subjectId" style='width: 200px;float: left'>
                            <a-select v-model="adjustmentCoursePutParams.subjectId" placeholder="请选择科目"
                                      :getPopupContainer="(target) => target.parentNode" @change="handleSubjectChange" style='width: 100%' >
                              <a-select-option v-for="item in subjectList" :key="item.value" style='width: 100%'>{{ item.label }}</a-select-option>
                            </a-select>

                          </a-form-model-item>
                        </a-col>
                        <a-col :span="24">
<!--                          <a-form-model-item label="老师" prop="teacherId">-->
<!--                            <j-dict-select-tag v-model='adjustmentCoursePutParams.teacherId' placeholder='请选择老师'-->
<!--                                               dictCode='tea_teacher,teacher_name,id' style='width: 100%'/>-->
<!--                          </a-form-model-item>-->
                          <a-form-model-item label="老师"  prop="teacherId"  style='width: 200px;float: left'>
                            <j-multi-select-tag :options="teacherList" v-model="adjustmentCoursePutParams.teacherId" placeholder="请选择老师"  style='width: 100%' >
                            </j-multi-select-tag>
                          </a-form-model-item>
                        </a-col>

                        <a-col :span="24">
                          <a-form-model-item label="教室" prop="classroomId" style='width: 200px;float: left'>
                            <j-dict-select-tag @change='changeBuildingId' v-model="adjustmentCoursePutParams.buildingId" placeholder="选择教学楼" dictCode="fac_building,building_name,id" style='width: 100%'/>
                            <j-dict-select-tag v-model='adjustmentCoursePutParams.classroomId' placeholder='请选择教室'
                                               :dictCode="adjustmentCourseQueryParamSelect.classroomIdSelect" style='width: 100%'/>
                          </a-form-model-item>
                        </a-col>
                        <a-col :span="24">
                          <a-form-model-item label="单双周" prop="courArraAtomIzSingle" style='width: 200px;float: left'>
                            <j-dict-select-tag v-model='adjustmentCoursePutParams.courArraAtomIzSingle' placeholder='请选择单双周'
                                               dictCode='cour_arra_atom_iz_single' style='width: 100%'/>
                          </a-form-model-item>
                        </a-col>
                      </a-card>
                    </a-col>
                  </a-row>
                </a-form-model-item>
              </a-col>
            </a-row>
          </a-modal>
        </div>

        <div>
          <a-modal title="编辑结果" :visible="adjustmentCourseStatusPutVisible" @ok="" @cancel="adjustmentCourseStatusPutVisible = false" width='40%'>
            <a-row>
              <template>
                <a-result
                  status="success"
                  title="恭喜您，课程编辑成功!"
                  sub-title=""
                >
                  <template #extra>
                  </template>
                </a-result>
              </template>
            </a-row>
          </a-modal>
        </div>
        <!-- ========编辑===============编辑课程对话框 -->

      </div>
    </a-row>
  </div>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { mixinDevice } from '@/utils/mixin'
import { deleteAction, getAction, putAction } from '@api/manage'
import { getTeacherCourseDataList } from '@api/couCourseArrangeAtom'
import { getSubjectList, queryTeacherListBySubject } from '@api/commonAPI'
import { deepClone } from '@/utils/util'


export default {
  // 课程表调课页面
  name: 'CouCourseArrangeAdjustment',
  mixins:[JeecgListMixin, mixinDevice],
  data () {
    return {
      description: 'v_cou_course_arrange_atom管理页面',
      url: {
        list: "/coursearrangeatom/couCourseArrangeAtom/#",
        //调换课程（两两调换）
        adjustmentArrangeAtomUpdate: "/coursearrangeatom/couCourseArrangeAtom/adjustmentArrangeAtomUpdate",
        //编辑课程（选中一节，新数据填充或修改已有数据）
        adjustmentArrangeAtomPut: "/coursearrangeatom/couCourseArrangeAtom/adjustmentArrangeAtomPut",
      },
      queryParamDictSelect1: {
        gradeIdSclect: "cou_grade,grade_name,id",
        classIdSclect: "cou_class cc,cc.class_name,cc.id,cc.class_iz_open  =1 and cc.class_iz_delete  =0 order by cc.grade_code !! cc.class_order !! cc.create_time",
        courseArrangeIdSclect: "cou_course_arrange,course_arrange_name,id",
        classroomIdSelect: "fac_classroom,classroom_name,id",

      },
      queryParamDictSelect2: {
        gradeIdSclect: "cou_grade,grade_name,id",
        classIdSclect: "cou_class cc,cc.class_name,cc.id,cc.class_iz_open  =1 and cc.class_iz_delete  =0 order by cc.grade_code !! cc.class_order !! cc.create_time",
        courseArrangeIdSclect: "cou_course_arrange,course_arrange_name,id",
        classroomIdSelect: "fac_classroom,classroom_name,id",
      },
      //下拉选择
      queryParam1: {
        gradeId: null,
        classId: null,
        courseArrangeId: null,
      },
      queryParam2: {
        gradeId: null,
        classId: null,
        courseArrangeId: null,

      },
      adjustmentCourseQueryParamSelect:{
        classroomIdSelect:"fac_classroom fc,fc.classroom_name,fc.id",
      },
      //ref部分
      objectModel: {},
      //课表科目查询
      //courseDataModel
      courseDataModelIndex: null,
      //左边第一个课表数据91条
      courseOneData1: [],
      courseOneData2: [],
      courseOneData3: [],
      courseOneData4: [],
      courseOneData5: [],
      courseOneData6: [],
      courseOneData7: [],
      //左边第二个课表数据91条
      courseTwoData1: [],
      courseTwoData2: [],
      courseTwoData3: [],
      courseTwoData4: [],
      courseTwoData5: [],
      courseTwoData6: [],
      courseTwoData7: [],

      //课表选择的行数据，在下方调课处显示的数据
      adjustmentCourseOneData: {
        // id: null,
        courseArrangeAtomId: null,
        courseArrangeId: null,
        classNicknameView: null,
        courArraAtomWeekday: null,
        courArraAtomSectionname: null,
        subjectName: null,
        teacherName: null,
        classNickname: null,
        classroom: null,
        courseArrangeStatus: null,
        courArraAtomIzSingle: null,
      },
      adjustmentCourseTwoData: {
        // id: null,
        courseArrangeAtomId: null,
        courseArrangeId: null,
        classNicknameView: null,
        courArraAtomWeekday: null,
        courArraAtomSectionname: null,
        subjectName: null,
        teacherName: null,
        classNickname: null,
        classroom: null,
        courseArrangeStatus: null,
        courArraAtomIzSingle: null,
      },
      adjustmentCourseThreeTempData: {},
      //调换课程对话框
      adjustmentCourseVisible: false,
      //调换模式key
      adjustmentCourseSelectKey: ['4','3'],
      //调换提交数据model
      couCourseArrangeAtom: [],
      adjustmentCourseStatusVisible: false,//调换成功打钩对话框
      //=========编辑课
      adjustmentCoursePutVisible: false,
      adjustmentCoursePutData: {
        id: null,
        courseArrangeId: null,
        classNicknameView: null,
        courArraAtomWeekday: null,
        courArraAtomSectionname: null,
        subjectName: null,
        teacherName: null,
        classNickname: null,
        classroom: null,
        courseArrangeStatus: null,
        courArraAtomIzSingle: null,
      },
      adjustmentCoursePutParams: {
        buildingId: null,
        classroomId: null,
      },
      adjustmentCourseStatusPutVisible: false,//编辑成功打钩对话框

      //编辑部分的科目 老师初始化变量
      subjectList: [],
      teacherList: [],



    }
  },
  created() {

    this.initSubjectList();
    // this.getTeacherLists();
    this.handleSubjectChange(); //初始化老师列表：默认全部老师
  },
  computed: {
    importExcelUrl: function(){
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    },
  },
  methods: {
    //查询条件变动
    changeGradeId1(){
      this.queryParamDictSelect1.classIdSclect = "cou_class cc,cc.class_name,cc.id,cc.class_iz_open  =1 and cc.class_iz_delete  =0 and cc.grade_code = \'"+this.queryParam1.gradeId+"\' order by cc.grade_code !! cc.class_order !! cc.create_time";
    },
    changeGradeId2(){
      this.queryParamDictSelect2.classIdSclect = "cou_class cc,cc.class_name,cc.id,cc.class_iz_open  =1 and cc.class_iz_delete  =0 and cc.grade_code = \'"+this.queryParam2.gradeId+"\' order by cc.grade_code !! cc.class_order !! cc.create_time";
    },
    changeClassId1(){
      this.queryParam1.courseArrangeId = null
      this.queryParamDictSelect1.courseArrangeIdSclect = "cou_course_arrange cca,course_arrange_name,id,cca.iz_open  =1 and cca.iz_delete  =0 and cca.target_obj_id = \'"+this.queryParam1.classId+"\' order by cca.school_year_id !! cca.semester_id !! cca.create_time";
    },
    changeClassId2(){
      this.queryParam2.courseArrangeId = null
      this.queryParamDictSelect2.courseArrangeIdSclect = "cou_course_arrange cca,course_arrange_name,id,cca.iz_open  =1 and cca.iz_delete  =0 and cca.target_obj_id = \'"+this.queryParam2.classId+"\' order by cca.school_year_id !! cca.semester_id !! cca.create_time";
    },
    //编辑课程：更改教学楼-->选择教室
    changeBuildingId(){
      if(this.adjustmentCoursePutParams.buildingId != null || this.adjustmentCoursePutParams.buildingId != ''){ //判断不为空
        this.adjustmentCourseQueryParamSelect.classroomIdSelect = "fac_classroom ac,ac.classroom_name,ac.id ,ac.building_id = \'"+ this.adjustmentCoursePutParams.buildingId + "\'" ;
      }
      if(this.adjustmentCoursePutParams.buildingId == null || this.adjustmentCoursePutParams.buildingId == ''){ //判断不为空
        this.adjustmentCourseQueryParamSelect.classroomIdSelect = "fac_classroom ac,ac.classroom_name,ac.id" ;
      }
    },
    async initSubjectList() {
      let subjectList = await getSubjectList()
      if (subjectList.code === 200) {
        this.subjectList = []
        subjectList.result.forEach(item => {
          this.subjectList.push({
            label: item.subjectName,
            value: item.subjectId
          })
        })
      }
    },
    async handleSubjectChange() {
      let tenantId = ''
      if (localStorage.length > 0) {
        let localData = JSON.parse(localStorage.getItem('pro__Login_Userinfo'))
        tenantId = localData.value.tenantId
        this.adjustmentCoursePutParams.tenantId = tenantId
      }
      let params = {
        tenantId: tenantId,
        subjectId: this.adjustmentCoursePutParams.subjectId
      }
      if (this.adjustmentCoursePutParams.subjectId !== null){
        let res = await queryTeacherListBySubject(params)
        if (res.success) {
          this.teacherList = []
          res.result.forEach(item => {
            this.teacherList.push({
              value: item.teacherId,
              label: item.teacherName
            })
          })
        }
      }
    },
    async getTeacherLists(){
      let getTeacherUrl = "/teacher/teaTeacher/queryTeacherLists"
      getAction(getTeacherUrl).then((res)=>{
        if (res.success) {
          this.teacherList = []
          res.result.forEach(item => {
            this.teacherList.push({
              value: item.id,
              label: item.teacherName
            })
          })
        }
      })
    },
    initDictConfig(){
    },
    getOrderMain(record) {
      //已选的一条完整标准数据
      this.objectModel = record //课表数据
      this.getCourseData();
    },
    //查询课表 - 仅课表查询数据
    handleGetDataChange(index){
      //当index=1 change的是左边第一个课表，index=2 hange的是右边第二个课表
      this.courseDataModelIndex = index
      if (index === 1 && this.queryParam1.classId != null && this.queryParam1.classId != ""){
        this.getCourseData(0)//查询形式：0查课表 1检测冲突
      }
      if (index === 2 && this.queryParam2.classId != null && this.queryParam2.classId != ""){
        this.getCourseData(0)//查询形式：0查课表 1检测冲突
      }
    },
    //查询课表 - 冲突检测数据
    handleGetDataChangeContradiction(index){
      //当index=1 change的是左边第一个课表，index=2 hange的是右边第二个课表
      this.courseDataModelIndex = index
      if (index === 1 && this.queryParam1.classId != null && this.queryParam1.classId != ""){
        this.getCourseData(1)//查询形式：0查课表 1检测冲突
      }
      if (index === 2 && this.queryParam2.classId != null && this.queryParam2.classId != ""){
        this.getCourseData(1)//查询形式：0查课表 1检测冲突
      }
    },
    //ttype类型 教师 没有无影响（废除时将前后端都要废除）
    async getCourseData(checkContradiction) {
       // checkContradiction 是否检查冲突：1是 0否
      var params;
      //this.courseDataModelIndex === 1 查的是第一个课表
      if (this.courseDataModelIndex === 1 && this.queryParam1.classId != null && this.queryParam1.classId != ""){
        params = {
          classId: this.queryParam1.classId,
          courseArrangeId: this.queryParam1.courseArrangeId,
          checkContradiction: checkContradiction
        }
        let res = await getTeacherCourseDataList(params)
        if (res && res.code === 200) {
          let datas = res.result
          this.courseOneData1 = datas.filter((item) => { item.selectIndex = false; return item.courArraAtomWeekday === 1 })
          this.courseOneData2 = datas.filter((item) => { item.selectIndex = false; return item.courArraAtomWeekday === 2 })
          this.courseOneData3 = datas.filter((item) => { item.selectIndex = false; return item.courArraAtomWeekday === 3 })
          this.courseOneData4 = datas.filter((item) => { item.selectIndex = false; return item.courArraAtomWeekday === 4 })
          this.courseOneData5 = datas.filter((item) => { item.selectIndex = false; return item.courArraAtomWeekday === 5 })
          this.courseOneData6 = datas.filter((item) => { item.selectIndex = false; return item.courArraAtomWeekday === 6 })
          this.courseOneData7 = datas.filter((item) => { item.selectIndex = false; return item.courArraAtomWeekday === 7 })
        } else {
          this.$message.error("暂无数据")
        }
      }
      //this.courseDataModelIndex === 2 查的是第一个课表
      if (this.courseDataModelIndex === 2 && this.queryParam2.classId != null && this.queryParam2.classId != ""){
        params = {
          classId: this.queryParam2.classId,
          courseArrangeId: this.queryParam2.courseArrangeId,
          checkContradiction: checkContradiction
        }
        let res = await getTeacherCourseDataList(params)
        if (res && res.code === 200) {
          let datas = res.result
          this.courseTwoData1 = datas.filter((item) => { item.selectIndex = false; return item.courArraAtomWeekday === 1 })
          this.courseTwoData2 = datas.filter((item) => { item.selectIndex = false; return item.courArraAtomWeekday === 2 })
          this.courseTwoData3 = datas.filter((item) => { item.selectIndex = false; return item.courArraAtomWeekday === 3 })
          this.courseTwoData4 = datas.filter((item) => { item.selectIndex = false; return item.courArraAtomWeekday === 4 })
          this.courseTwoData5 = datas.filter((item) => { item.selectIndex = false; return item.courArraAtomWeekday === 5 })
          this.courseTwoData6 = datas.filter((item) => { item.selectIndex = false; return item.courArraAtomWeekday === 6 })
          this.courseTwoData7 = datas.filter((item) => { item.selectIndex = false; return item.courArraAtomWeekday === 7 })
        } else {
          this.$message.error("暂无数据")
        }
      }
    },
    //清空选择
    clearSelectOne(){
      this.adjustmentCourseOneData = {};//清空
      this.adjustmentCourseOneData.id = null;//只是用来判断是否清空
    },
    clearSelectTwo(){
      this.adjustmentCourseTwoData = {};//清空
      this.adjustmentCourseTwoData.id = null;//只是用来判断是否清空

    },

    //选择
    selectBt(item,index){
      // if (index === 1){}
        //已选中再次点击会取消
        if( item.arrangeContradictionColor === '#00bb33' || item.arrangeContradictionColor === '#11ff44'){
          item.arrangeContradictionColor = null
          if( this.adjustmentCourseTwoData && this.adjustmentCourseTwoData.courseArrangeAtomId ){
            this.adjustmentCourseOneData.arrangeContradictionColor = null;
            this.adjustmentCourseOneData = {};//清空
            this.adjustmentCourseOneData = this.adjustmentCourseTwoData
            this.adjustmentCourseOneData.arrangeContradictionColor = '#11ff44'
            this.adjustmentCourseTwoData = {};//清空
          }
          // else if( ( !this.adjustmentCourseTwoData || !this.adjustmentCourseTwoData.courseArrangeAtomId) && (!this.adjustmentCourseTwoData || !this.adjustmentCourseTwoData.courseArrangeAtomId)){
          else{
            this.adjustmentCourseOneData = {};//清空
            this.adjustmentCourseTwoData = {};//清空
          }


        }
        //选中
        else{
          if(! this.adjustmentCourseOneData || !this.adjustmentCourseOneData.courseArrangeAtomId){
            item.arrangeContradictionColor = '#11ff44'
            this.adjustmentCourseOneData = item
          }
          else if( !this.adjustmentCourseTwoData || !this.adjustmentCourseTwoData.courseArrangeAtomId){
            item.arrangeContradictionColor = '#00bb33'
            this.adjustmentCourseTwoData = item
          }
          else {
            //选中第三个
            this.adjustmentCourseOneData.arrangeContradictionColor = null //取消选择颜色设置
            this.adjustmentCourseOneData = null
            // this.adjustmentCourseThreeTempData = deepClone(this.adjustmentCourseTwoData) //临时变量，用于取消选择
            this.adjustmentCourseOneData = this.adjustmentCourseTwoData
            this.adjustmentCourseOneData.arrangeContradictionColor = '#11ff44'

            item.arrangeContradictionColor = '#00bb33'
            this.adjustmentCourseTwoData = item
          }
        }
        console.log("this.adjustmentCourseOneData="+this.adjustmentCourseOneData.courseArrangeAtomId+",this.adjustmentCourseTwoData="+this.adjustmentCourseTwoData.courseArrangeAtomId)


      // if (index === 2){
      //   item.arrangeContradictionColor = '#11ff44'
      //   // this.adjustmentCourseTwoData = item
      // }
    },
    //对话框
    adjustmentCourseModal(){
      //判断选择是选择情况以及课表状态（已发布、已下线的课表不允许调换）
      if (!this.adjustmentCourseOneData.courseArrangeAtomId || !this.adjustmentCourseTwoData.courseArrangeAtomId){
        alert("请先选择两组调换的课程")
        return
      }else if(this.adjustmentCourseOneData.courseArrangeStatus === "4" || this.adjustmentCourseOneData.courseArrangeStatus === "5"){
        alert("“已发布或已下线”的课表，不可调换")
        return
      }else if(this.adjustmentCourseTwoData.courseArrangeStatus === "4" || this.adjustmentCourseTwoData.courseArrangeStatus === "5"){
        alert("“已发布或已下线”的课表，不可调换")
        return
      }
      else {
        this.adjustmentCourseVisible = true
      }
    },
    //调课对话框提交OK及处理
    handleAdjustmentCourseOk(){
      if (this.adjustmentCourseSelectKey.length <= 0){
        alert("调换模式至少要选择一项课程的调换项：如科目、教师、教室、单双周等...")
      }else {
        this.adjustmentCourseOneData.atomType = this.adjustmentCourseSelectKey
        this.adjustmentCourseTwoData.atomType = this.adjustmentCourseSelectKey
        let params = {
          couCourseArrangeAtomOne : this.adjustmentCourseOneData,
          couCourseArrangeAtomTwo : this.adjustmentCourseTwoData,
        }
        putAction(this.url.adjustmentArrangeAtomUpdate,params).then((res) => {
          if (res.success){
            this.$message.success("恭喜您，调课成功")
            this.adjustmentCourseVisible = false;//调换成功即关闭对话框
            this.adjustmentCourseStatusVisible = true;//调换成功随即打开成功打钩结果对话框
            // 过500毫秒调用
            setTimeout(() => {
              // 方法区
              this.adjustmentCourseStatusVisible = false;
            }, 800);
            //清空选择
            this.clearSelectOne();
            this.clearSelectTwo();
          }else {
            this.$message.error("调课失败，数据有误！")
          }
        });
      }
    },
    //全选
    allSelectKey(){
      this.adjustmentCourseSelectKey = ['4','3','2','7']
    },


    //编辑课
    //对话框
    adjustmentCoursePutModal(){
      if (! this.adjustmentCourseOneData.courseArrangeAtomId && !this.adjustmentCourseTwoData.courseArrangeAtomId ){
        alert("请先选择一组需要编辑的课程")
        return
      }
      if (this.adjustmentCourseOneData.courseArrangeAtomId && this.adjustmentCourseTwoData.courseArrangeAtomId ){
        alert("编辑时只能选择一组课程")
        return
      }
      if(this.adjustmentCourseOneData.courseArrangeStatus === "4" || this.adjustmentCourseOneData.courseArrangeStatus === "5"){
        alert("“已发布或已下线”的课表，不可编辑")
        return
      }else if(this.adjustmentCourseTwoData.courseArrangeStatus === "4" || this.adjustmentCourseTwoData.courseArrangeStatus === "5"){
        alert("“已发布或已下线”的课表，不可编辑")
        return
      }
      else {
        if (this.adjustmentCourseOneData.id !== null){
          this.adjustmentCoursePutData = this.adjustmentCourseOneData
        }else if(this.adjustmentCourseTwoData.id !== null){
          this.adjustmentCoursePutData = this.adjustmentCourseTwoData
        }
        this.adjustmentCoursePutVisible = true
      }
    },
    //编辑课程 提交
    handleAdjustmentCoursePutOk(){
      //课表状态：(来自字典码：1初始 2预排课 3已排课 4已发布 5已下线 6需重排)
      if (this.adjustmentCourseSelectKey.length <= 0){
        alert("调换模式至少要选择一项课程的调换项：如科目、教师、教室、单双周等...")
      }else {
        this.adjustmentCoursePutData.atomType = this.adjustmentCourseSelectKey
        this.adjustmentCoursePutParams.atomType = this.adjustmentCourseSelectKey
        let params = {
          adjustmentCoursePutData : this.adjustmentCoursePutData,
          adjustmentCoursePutParams : this.adjustmentCoursePutParams,
        }
        putAction(this.url.adjustmentArrangeAtomPut,params).then((res) => {
          if (res.success){
            this.$message.success("恭喜您，编辑成功")
            this.adjustmentCoursePutVisible = false;//编辑成功即关闭对话框
            this.adjustmentCourseStatusPutVisible = true;//编辑成功随即打开成功打钩结果对话框
            // 过500毫秒调用
            setTimeout(() => {
              // 方法区
              this.adjustmentCourseStatusPutVisible = false;
            }, 800);
            //清空选择
            this.clearSelectOne();
            this.clearSelectTwo();
          }else {
            this.$message.error("调课失败，数据有误！")
          }
        });
      }
    },


  }
}
</script>

<style scoped>
.week-t {
  background-color: rgba(0,150,94,.1);
  height: 40px;

  color: #151515;
  line-height: 40px;
  font-weight: bold;
}
.week-c {
  height: 45px;
  border-top: 1px solid #e2e2e2;
  border-right: 1px solid #e2e2e2;
  line-height: 17px;
  font-size: 12px;
}
.week-c:hover {
  background-color: #45aff6;
  transition: all 0.5s;
}
.select-box {
  z-index: 9999;
  font-size: 18px;
  color: #ffffff;
  border-radius: 50px;
  padding: 5px;
  display: flex;
  position: absolute;
  background: #09ad4b;
  width: 27px;
  height: 27px;
}
@import '~@assets/less/common.less';
</style>